package com.zbest.zpay.paycore.dal.dao;

import javax.annotation.Resource;

import org.apache.ibatis.annotations.Param;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;

import com.zbest.common.lang.enums.BizCode;
import com.zbest.common.lang.exception.ZpayException;
import com.zbest.zpay.paycore.dal.mapper.PayInfoMapper;
import com.zbest.zpay.paycore.dal.model.PayInfoDO;

/**
 * Created by wenfeihu on 16/5/20.
 */
@Service("payInfoDAO")
public class PayInfoDAO {

    @Resource
    private PayInfoMapper payInfoMapper;

    public void insert(PayInfoDO payInfoDO) {

        try {
            payInfoMapper.insert(payInfoDO);
        } catch (DataIntegrityViolationException e) {
            throw new ZpayException(BizCode.DUPLICATED_ERROR);
        }

    }

    public void updateStatus(String payInfoId, String destStatus, String srcStatus) {

        int row = payInfoMapper.updateStatus(payInfoId, destStatus, srcStatus);
        if (row <= 0) {
            throw new ZpayException(BizCode.DATA_NOT_EXISTS);
        }

    }

    public PayInfoDO query(@Param("payInfoId") String payInfoId) {
        return payInfoMapper.query(payInfoId);
    }
}
